import axios from 'axios'

axios.defaults.baseURL = 'http://127.0.0.1:3000/api'

axios.interceptors.request.use(config => {
    return config;
})

axios.interceptors.response.use(res => {
    if (res.request.status == 200 && res.data.code == 200) return res.data;
    else {
        return Promise.reject(res.data.msg)
    }
})

export function get(params, url) {
    return axios.get(url, {
        params: params
    })
}

export function post(url, params) {
    return axios.post(url, params)
}